<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>iServer MVT矢量瓦片(4326坐标系)</title>
    <script type="text/javascript" src="../../dist/include-openlayers.js"></script>
</head>
<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%">
<div id="map" style="margin:0 auto;width: 100%;height: 100%;border: 1px solid #dddddd"></div>
<script type="text/javascript">
    var url = (window.isLocal ? document.location.protocol + "//" + document.location.host : "http://117.122.248.69:8090")+"/iserver/services/map-world/rest/maps/World";
    new ol.supermap.MapService(url).getMapInfo(function (serviceResult) {
        var map = new ol.Map({
            target: 'map',
            controls: ol.control.defaults({attributionOptions: {collapsed: false}})
                .extend([new ol.supermap.control.Logo()]),
            view: new ol.View({
                center: [0, 0],
                zoom: 2,
                projection: 'EPSG:4326'
            }),
        });
        var stylesOptions = {
            url: url,
            view: map.getView()
        }
        var vectorTileStyles = new ol.supermap.VectorTileStyles(stylesOptions);
        var vectorTileOptions = ol.source.VectorTileSuperMapRest.optionsFromMapJSON(url, serviceResult.result);
        vectorTileOptions.format = new ol.format.MVT({featureClass: ol.Feature});
        var vectorLayer = new ol.layer.VectorTile({
            source: new ol.source.VectorTileSuperMapRest(vectorTileOptions),
            style: vectorTileStyles.getFeatureStyle
        });
        map.addLayer(vectorLayer);

        map.on('click', function (e) {
            map.forEachFeatureAtPixel(e.pixel, function (feature) {
                vectorTileStyles.dispatchEvent({type: 'featureSelected',
                    selectedId: feature.getId(),
                    layerName: feature.getProperties().layer
                });
                return true;
            }, {hitTolerance: 5});
            vectorLayer.changed();
        })

    });
</script>
</body>
</html>